package com.framework.modules.appindex;

import com.framework.entity.or.OrBanner;
import com.framework.entity.sys.SysDeptJumpUrl;
import com.framework.exception.util.RespResult;
import com.framework.modules.sys.controller.AbstractController;
import com.framework.page.PageUtils;
import com.framework.service.BannerService;
import com.framework.service.SysDeptJumpUrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * 课堂控制器
 * @author wq
 */
@RestController
@RequestMapping("sys/orLesson")
public class OrLessonController extends AbstractController {

    @Autowired
    private SysDeptJumpUrlService sysDeptJumpUrlService;
    @Autowired
    private BannerService bannerService;
    /**
     * 课程分页
     * @param params
     * @return
     */
    @RequestMapping("/list")
    public RespResult queryLessonPage(@RequestParam Map<String,Object> params){
        params.put("deptId",getUser().getDeptId());
        PageUtils page = bannerService.queryLessonPageByBanner(params);
        return  RespResult.ok().put("page",page);
    }

    /**
     * 根据id获取
     * @param bannerId
     * @return
     */
    @RequestMapping("/getById/{bannerId}")
    public RespResult getById(@PathVariable Long bannerId){
        OrBanner banner = bannerService.selectById(bannerId);
        return RespResult.ok().put("banner",banner);
    }

    /**
     * 修改
     * @param banner
     * @return
     */
    @RequestMapping("/update")
    public RespResult updateLesson(@RequestBody OrBanner banner){
        Long deptId=getDeptId();
        banner.setCreateDate(new Date());
        banner.setDeptId(deptId);
        if(banner.getType().intValue()!=4){
            banner.setJumpType(2);
        }
        SysDeptJumpUrl t = sysDeptJumpUrlService.queryByDeptIdAndType(deptId,1);
        banner.setJumpUrl(t.getBannerJump());
        bannerService.updateById(banner);
        return RespResult.ok();
    }

    /**
     * 添加
     * @param
     * @return
     */
    @RequestMapping("/add")
    public RespResult addLesson(@RequestBody OrBanner banner){
        Long deptId=getDeptId();
        banner.setCreateDate(new Date());
        banner.setDeptId(deptId);
        if(banner.getType().intValue()!=4){
            banner.setJumpType(2);
        }
        SysDeptJumpUrl t = sysDeptJumpUrlService.queryByDeptIdAndType(deptId,1);
        banner.setJumpUrl(t.getBannerJump());
        bannerService.insert(banner);
        return RespResult.ok();
    }

}
